package com.project.controller;

import com.project.bean.SaleCartBean;
import com.project.bean.UserBean;
import com.project.service.ISaleCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("saleCart")
@Api(tags = "销售车控制器")
public class SaleCartController {
    @Autowired
    private ISaleCartService saleCartService;
    @ApiOperation("查询登陆用户销售车信息")
    @RequestMapping("findByUserId")
    @RequiresPermissions("sale:add")
    public List<SaleCartBean> findByUserId(HttpServletRequest req){
        UserBean loginUser =(UserBean) req.getSession().getAttribute("loginUser");
      return  saleCartService.findByUserId(loginUser.getId());
    }
    @ApiOperation("按编号删除销售车记录")
    @ApiImplicitParam(name="id",value = "销售车编号")
    @RequestMapping("del")
    public String del(Integer id){
        saleCartService.del(id);
        return "ok";
    }

    @RequestMapping("add")
    @ApiOperation("添加商品到销售车")
    @RequiresPermissions("sale:add")
    public String add(SaleCartBean saleCart,HttpServletRequest req){
        UserBean loginUser =(UserBean) req.getSession().getAttribute("loginUser");
        saleCart.setUserId(loginUser.getId());
        saleCartService.add(saleCart);
        return "ok";
    }
    @ApiOperation(value ="修改销售车数量",notes = "按编号修改销售车数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "编号",required = true),
            @ApiImplicitParam(name="num",value = "销售数量",required = true)
    })
    @RequestMapping("update")
    @RequiresPermissions("sale:add")
    public String update(Integer id, Integer num){
        saleCartService.update(id,num);
        return "ok";
    }

}
